using System;
using System.Windows.Forms;
using Belmost4PDA.Constants;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public class StateEdit:AbstractState
    {
        public override bool CanDo(AbstractCommand command)
        {
            bool Desision = true;
            CommandID id = command.GetID();
            switch(id)
            {   
                case CommandID.Insert:
                case CommandID.Delete:
                case CommandID.Edit:
                    Desision=false; break;

                case CommandID.Exit:
                case CommandID.Post:
                case CommandID.ChangeParam:
                case CommandID.Cancel:
                    break;
            }
            return Desision && base.CanDo(command);
        }
        public override bool AskToDo(AbstractCommand command)
        {
            CommandID id = command.GetID();
            switch (id)
            {
                case CommandID.ReadData:
                case CommandID.Exit:
                case CommandID.ChangeParam:
                case CommandID.Cancel:
                   if(dialog.CommitCancel()) return true;
                   else return false;
                default:
                    return true;
            }
        }

        public override void SetupControls(Form form)
        {
            foreach (Control o in form.Controls)
            {
                IReadOnly check=o as IReadOnly;
                if (check!=null)
                    check.ROnly = false;
                else
                    if (o.GetType() != typeof(Button) && o.GetType() != typeof(Label)&&o.GetType()!=typeof(HintView))
                    o.Enabled = false;

            }

            if (form.Menu != null) CheckMenu(form.Menu);
        }
    }
}
